import os
from PIL import Image, ImageDraw, ImageFont

def create_default_avatar():
    """创建默认头像"""
    # 创建一个圆形头像
    size = 200
    img = Image.new('RGBA', (size, size), (0, 0, 0, 0))
    draw = ImageDraw.Draw(img)
    
    # 绘制圆形背景
    draw.ellipse([0, 0, size-1, size-1], fill='#ff6b9d', outline='#e91e63', width=2)
    
    # 绘制用户图标（简单的人形）
    # 头部
    head_size = 40
    head_x = (size - head_size) // 2
    head_y = size // 3
    draw.ellipse([head_x, head_y, head_x + head_size, head_y + head_size], fill='white')
    
    # 身体
    body_width = 60
    body_height = 50
    body_x = (size - body_width) // 2
    body_y = head_y + head_size + 10
    draw.ellipse([body_x, body_y, body_x + body_width, body_y + body_height], fill='white')
    
    return img

def create_empty_image():
    """创建空状态图片"""
    size = (300, 200)
    img = Image.new('RGBA', size, (0, 0, 0, 0))
    draw = ImageDraw.Draw(img)
    
    # 绘制空盒子图标
    box_width = 80
    box_height = 60
    box_x = (size[0] - box_width) // 2
    box_y = (size[1] - box_height) // 2 - 20
    
    # 盒子主体
    draw.rectangle([box_x, box_y, box_x + box_width, box_y + box_height], 
                  outline='#ccc', width=2, fill='#f5f5f5')
    
    # 盒子盖子
    lid_height = 10
    draw.rectangle([box_x - 5, box_y - lid_height, box_x + box_width + 5, box_y], 
                  outline='#ccc', width=2, fill='#e0e0e0')
    
    # 添加文字（如果有字体的话）
    try:
        font = ImageFont.truetype("arial.ttf", 16)
    except:
        font = ImageFont.load_default()
    
    text = "暂无数据"
    text_bbox = draw.textbbox((0, 0), text, font=font)
    text_width = text_bbox[2] - text_bbox[0]
    text_x = (size[0] - text_width) // 2
    text_y = box_y + box_height + 20
    
    draw.text((text_x, text_y), text, fill='#999', font=font)
    
    return img

def main():
    # 确保目录存在
    frontend_images_dir = '../frontend/images'
    os.makedirs(frontend_images_dir, exist_ok=True)
    
    # 创建默认头像
    avatar_img = create_default_avatar()
    avatar_path = os.path.join(frontend_images_dir, 'default-avatar.png')
    avatar_img.save(avatar_path, 'PNG')
    print(f"创建默认头像: {avatar_path}")
    
    # 创建空状态图片
    empty_img = create_empty_image()
    empty_path = os.path.join(frontend_images_dir, 'empty.png')
    empty_img.save(empty_path, 'PNG')
    print(f"创建空状态图片: {empty_path}")
    
    print("图片创建完成！")

if __name__ == '__main__':
    main()